package com.itheima.array2;

import java.util.Scanner;

public class PingWeiDaFen {
    public static void main(String[] args) {
        //1.定义一个数组，用动态初始化完成数组元素的初始化，长度为6
        int[] arr = new int[6];
        //2.键盘录入评委分数
        Scanner sc = new Scanner(System.in);

        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入" + (i+1) + "个评委的打分:");
            int score = sc.nextInt();
            if (score >= 0 && score <= 100){
                //合法分数
                arr[i] = score;
            }else{
                //非法的分值
                System.out.println("您的打分输入有误，请检查是否是0-100之间");
                i--;
            }
        }

        //4.求出数组最大值
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (max < arr[i]){
                max = arr[i];
            }
        }

        //5.求出数组最小值
        int min = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (min > arr[i]){
                min = arr[i];
            }
        }

        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }

        //7.按照计算规则进行计算得到平均分
        double avg = (sum - max - min) / (arr.length - 2);
        //8.输出平均值
        System.out.println("平均分为：" + avg);
    }
}
